<?php
define("EW_PAGE_ID", "list", TRUE); // Page ID
define("EW_TABLE_NAME", 'tb_locations', TRUE);
?>
<?php 
session_start(); // Initialize session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg50.php" ?>
<?php include "ewmysql50.php" ?>
<?php include "phpfn50.php" ?>
<?php include "tb_locationsinfo.php" ?>
<?php include "userfn50.php" ?>
<?php include "tb_usersinfo.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Open connection to the database
$conn = ew_Connect();
?>
<?php
$Security = new cAdvancedSecurity();
?>
<?php
if (!$Security->IsLoggedIn()) $Security->AutoLogin();
if (!$Security->IsLoggedIn()) {
	$Security->SaveLastUrl();
	Page_Terminate("login.php");
}
?>
<?php

// Common page loading event (in userfn*.php)
Page_Loading();
?>
<?php

// Page load event, used in current page
Page_Load();
?>
<?php
$tb_locations->Export = @$_GET["export"]; // Get export parameter
$sExport = $tb_locations->Export; // Get export parameter, used in header
$sExportFile = $tb_locations->TableVar; // Get export file, used in header
?>
<?php
if ($tb_locations->Export == "excel") {
	header('Content-Type: application/vnd.ms-excel');
	header('Content-Disposition: attachment; filename=' . $sExportFile .'.xls');
}
if ($tb_locations->Export == "csv") {
	header('Content-Type: application/csv');
	header('Content-Disposition: attachment; filename=' . $sExportFile .'.csv');
}
?>
<?php

// Paging variables
$nStartRec = 0; // Start record index
$nStopRec = 0; // Stop record index
$nTotalRecs = 0; // Total number of records
$nDisplayRecs = 20;
$nRecRange = 10;
$nRecCount = 0; // Record count

// Search filters
$sSrchAdvanced = ""; // Advanced search filter
$sSrchBasic = ""; // Basic search filter
$sSrchWhere = ""; // Search where clause
$sFilter = "";

// Master/Detail
$sDbMasterFilter = ""; // Master filter
$sDbDetailFilter = ""; // Detail filter
$sSqlMaster = ""; // Sql for master record

// Handle reset command
ResetCmd();

// Check QueryString parameters
if (@$_GET["a"] <> "") {
	$tb_locations->CurrentAction = $_GET["a"];

	// Clear inline mode
	if ($tb_locations->CurrentAction == "cancel") {
		ClearInlineMode();
	}

	// Switch to grid edit mode
	if ($tb_locations->CurrentAction == "gridedit") {
		GridEditMode();
	}

	// Switch to inline add mode
	if ($tb_locations->CurrentAction == "add" || $tb_locations->CurrentAction == "copy") {
		InlineAddMode();
	}
} else {

	// Create form object
	$objForm = new cFormObj;
	if (@$_POST["a_list"] <> "") {
		$tb_locations->CurrentAction = $_POST["a_list"]; // Get action

		// Grid Update
		if ($tb_locations->CurrentAction == "gridupdate" && @$_SESSION[EW_SESSION_INLINE_MODE] == "gridedit") {
			GridUpdate();
		}

		// Insert Inline
		if ($tb_locations->CurrentAction == "insert" && @$_SESSION[EW_SESSION_INLINE_MODE] == "add") {
			InlineInsert();
		}
	}
}

// Get basic search criteria
$sSrchBasic = BasicSearchWhere();

// Build search criteria
if ($sSrchAdvanced <> "") {
	if ($sSrchWhere <> "") $sSrchWhere .= " AND ";
	$sSrchWhere .= "(" . $sSrchAdvanced . ")";
}
if ($sSrchBasic <> "") {
	if ($sSrchWhere <> "") $sSrchWhere .= " AND ";
	$sSrchWhere .= "(" . $sSrchBasic . ")";
}

// Save search criteria
if ($sSrchWhere <> "") {
	if ($sSrchBasic == "") ResetBasicSearchParms();
	$tb_locations->setSearchWhere($sSrchWhere); // Save to Session
	$nStartRec = 1; // Reset start record counter
	$tb_locations->setStartRecordNumber($nStartRec);
} else {
	RestoreSearchParms();
}

// Build filter
$sFilter = "";
if ($sDbDetailFilter <> "") {
	if ($sFilter <> "") $sFilter .= " AND ";
	$sFilter .= "(" . $sDbDetailFilter . ")";
}
if ($sSrchWhere <> "") {
	if ($sFilter <> "") $sFilter .= " AND ";
	$sFilter .= "(" . $sSrchWhere . ")";
}

// Set up filter in Session
$tb_locations->setSessionWhere($sFilter);
$tb_locations->CurrentFilter = "";

// Set Up Sorting Order
SetUpSortOrder();

// Export data only
if ($tb_locations->Export == "xml" || $tb_locations->Export == "csv") {
	ExportData();
	Page_Terminate(); // Terminate response
}

// Set Return Url
$tb_locations->setReturnUrl("tb_locationslist.php");
?>
<?php include "header.php" ?>
<?php if ($tb_locations->Export == "") { ?>
<script type="text/javascript">
<!--
var EW_PAGE_ID = "list"; // Page id

//-->
</script>
<script type="text/javascript">
<!--

function ew_ValidateForm(fobj) {
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_LocationName"];
		if (elm && !ew_HasValue(elm)) {
			if (!ew_OnError(elm, "Please enter required field - Location Name"))
				return false;
		}
		elm = fobj.elements["x" + infix + "_LocationRent"];
		if (elm && !ew_CheckNumber(elm.value)) {
			if (!ew_OnError(elm, "Incorrect floating point number - Location Rent"))
				return false; 
		}
		elm = fobj.elements["x" + infix + "_PayRoll"];
		if (elm && !ew_CheckNumber(elm.value)) {
			if (!ew_OnError(elm, "Incorrect floating point number - Pay Roll"))
				return false; 
		}
		elm = fobj.elements["x" + infix + "_Utilities"];
		if (elm && !ew_CheckNumber(elm.value)) {
			if (!ew_OnError(elm, "Incorrect floating point number - Utilities"))
				return false; 
		}
	}
	return true;
}

//-->
</script>
<script type="text/javascript">
<!--
var firstrowoffset = 1; // First data row start at
var lastrowoffset = 0; // Last data row end at
var EW_LIST_TABLE_NAME = 'ewlistmain'; // Table name for list page
var rowclass = 'ewTableRow'; // Row class
var rowaltclass = 'ewTableAltRow'; // Row alternate class
var rowmoverclass = 'ewTableHighlightRow'; // Row mouse over class
var rowselectedclass = 'ewTableSelectRow'; // Row selected class
var roweditclass = 'ewTableEditRow'; // Row edit class

//-->
</script>
<script type="text/javascript">
<!--
var ew_DHTMLEditors = [];

//-->
</script>
<script type="text/javascript">
<!--

function ew_SelectKey(elem) {
	var f = elem.form;	
	if (!f.elements["key_m[]"]) return;
	if (f.elements["key_m[]"][0]) {
		for (var i=0; i<f.elements["key_m[]"].length; i++)
			f.elements["key_m[]"][i].checked = elem.checked;	
	} else {
		f.elements["key_m[]"].checked = elem.checked;	
	}
	ew_ClickAll(elem);
}

function ew_Selected(f) {
	if (!f.elements["key_m[]"]) return false;
	if (f.elements["key_m[]"][0]) {
		for (var i=0; i<f.elements["key_m[]"].length; i++)
			if (f.elements["key_m[]"][i].checked) return true;
	} else {
		return f.elements["key_m[]"].checked;
	}
	return false;
}

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<?php } ?>
<?php if ($tb_locations->Export == "") { ?>
<?php } ?>
<?php

// Load recordset
$bExportAll = (defined("EW_EXPORT_ALL") && $tb_locations->Export <> "");
$bSelectLimit = ($tb_locations->Export == "" && $tb_locations->SelectLimit);
if (!$bSelectLimit) $rs = LoadRecordset();
$nTotalRecs = ($bSelectLimit) ? $tb_locations->SelectRecordCount() : $rs->RecordCount();
$nStartRec = 1;
if ($nDisplayRecs <= 0) $nDisplayRecs = $nTotalRecs; // Display all records
if (!$bExportAll) SetUpStartRec(); // Set up start record position
if ($bSelectLimit) $rs = LoadRecordset($nStartRec-1, $nDisplayRecs);
?>
<p><span class="phpmaker" style="white-space: nowrap;">TABLE: Locations
<?php if ($tb_locations->Export == "") { ?>
&nbsp;&nbsp;<a href="tb_locationslist.php?export=excel">Export to Excel</a>
&nbsp;&nbsp;<a href="tb_locationslist.php?export=csv">Export to CSV</a>
<?php } ?>
</span></p>
<?php if ($tb_locations->Export == "") { ?>
<?php if ($Security->IsLoggedIn()) { ?>
<form name="ftb_locationslistsrch" id="ftb_locationslistsrch" action="tb_locationslist.php" >
<table class="ewBasicSearch">
	<tr>
		<td><span class="phpmaker">
			<input type="text" name="<?php echo EW_TABLE_BASIC_SEARCH ?>" id="<?php echo EW_TABLE_BASIC_SEARCH ?>" size="20" value="<?php echo $tb_locations->getBasicSearchKeyword() ?>">
			<input type="Submit" name="Submit" id="Submit" value="Search (*)">&nbsp;
			<a href="tb_locationslist.php?cmd=reset">Show all</a>&nbsp;
		</span></td>
	</tr>
	<tr>
	<td><span class="phpmaker"><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value="" <?php if ($tb_locations->getBasicSearchType() == "") { ?>checked<?php } ?>>Exact phrase&nbsp;&nbsp;<input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value="AND" <?php if ($tb_locations->getBasicSearchType() == "AND") { ?>checked<?php } ?>>All words&nbsp;&nbsp;<input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value="OR" <?php if ($tb_locations->getBasicSearchType() == "OR") { ?>checked<?php } ?>>Any word</span></td>
	</tr>
</table>
</form>
<?php } ?>
<?php } ?>
<?php
if (@$_SESSION[EW_SESSION_MESSAGE] <> "") {
?>
<p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
<?php
	$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message
}
?>
<form name="ftb_locationslist" id="ftb_locationslist" action="tb_locationslist.php" method="post">
<?php if ($tb_locations->Export == "") { ?>
<table>
	<tr><td><span class="phpmaker">
<?php if ($tb_locations->CurrentAction <> "gridedit") { // Not grid edit mode ?>
<?php if ($Security->IsLoggedIn()) { ?>
<a href="tb_locationsadd.php">Add</a>&nbsp;&nbsp;
<a href="tb_locationslist.php?a=add">Inline Add</a>&nbsp;&nbsp;
<?php } ?>
<?php if ($nTotalRecs > 0) { ?>
<?php if ($Security->IsLoggedIn()) { ?>
<a href="" onClick="if (!ew_Selected(document.ftb_locationslist)) alert('No records selected'); else {document.ftb_locationslist.action='tb_locationsupdate.php';document.ftb_locationslist.encoding='application/x-www-form-urlencoded';document.ftb_locationslist.submit();};return false;">Update Selected Records</a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<?php if ($nTotalRecs > 0) { ?>
<a href="tb_locationslist.php?a=gridedit">Grid Edit</a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php } else { // Grid edit mode ?>
<a href="" onClick="if (ew_ValidateForm(document.ftb_locationslist)) document.ftb_locationslist.submit();return false;">Save</a>&nbsp;&nbsp;
<a href="tb_locationslist.php?a=cancel">Cancel</a>&nbsp;&nbsp;
<?php } ?>
	</span></td></tr>
</table>
<?php } ?>
<?php if ($nTotalRecs > 0 || $tb_locations->CurrentAction == "add" || $tb_locations->CurrentAction == "copy") { ?>
<table id="ewlistmain" class="ewTable">
<?php
	$OptionCnt = 0;
if ($Security->IsLoggedIn()) {
	$OptionCnt++; // view
}
if ($Security->IsLoggedIn()) {
	$OptionCnt++; // edit
}
if ($Security->IsLoggedIn()) {
	$OptionCnt++; // copy
}
if ($Security->IsLoggedIn()) {
	$OptionCnt++; // delete
}
if ($Security->IsLoggedIn()) {
	$OptionCnt++; // multi select
}
?>
	<!-- Table header -->
	<tr class="ewTableHeader">
		<td valign="top">
<?php if ($tb_locations->Export <> "") { ?>
ID
<?php } else { ?>
	<a href="tb_locationslist.php?order=<?php echo urlencode('ID') ?>&ordertype=<?php echo $tb_locations->ID->ReverseSort() ?>">ID<?php if ($tb_locations->ID->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($tb_locations->ID->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></a>
<?php } ?>
		</td>
		<td valign="top">
<?php if ($tb_locations->Export <> "") { ?>
Location Name
<?php } else { ?>
	<a href="tb_locationslist.php?order=<?php echo urlencode('LocationName') ?>&ordertype=<?php echo $tb_locations->LocationName->ReverseSort() ?>">Location Name&nbsp;(*)<?php if ($tb_locations->LocationName->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($tb_locations->LocationName->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></a>
<?php } ?>
		</td>
		<td valign="top">
<?php if ($tb_locations->Export <> "") { ?>
Location Rent
<?php } else { ?>
	<a href="tb_locationslist.php?order=<?php echo urlencode('LocationRent') ?>&ordertype=<?php echo $tb_locations->LocationRent->ReverseSort() ?>">Location Rent<?php if ($tb_locations->LocationRent->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($tb_locations->LocationRent->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></a>
<?php } ?>
		</td>
		<td valign="top">
<?php if ($tb_locations->Export <> "") { ?>
Pay Roll
<?php } else { ?>
	<a href="tb_locationslist.php?order=<?php echo urlencode('PayRoll') ?>&ordertype=<?php echo $tb_locations->PayRoll->ReverseSort() ?>">Pay Roll<?php if ($tb_locations->PayRoll->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($tb_locations->PayRoll->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></a>
<?php } ?>
		</td>
		<td valign="top">
<?php if ($tb_locations->Export <> "") { ?>
Utilities
<?php } else { ?>
	<a href="tb_locationslist.php?order=<?php echo urlencode('Utilities') ?>&ordertype=<?php echo $tb_locations->Utilities->ReverseSort() ?>">Utilities<?php if ($tb_locations->Utilities->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($tb_locations->Utilities->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></a>
<?php } ?>
		</td>
<?php if ($tb_locations->Export == "") { ?>
<?php if ($tb_locations->CurrentAction <> "gridedit") { ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap>&nbsp;</td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap>&nbsp;</td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap>&nbsp;</td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<?php if ($OptionCnt == 0 && $tb_locations->CurrentAction == "add") { ?>
<td nowrap>&nbsp;</td>
<?php } ?>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap>&nbsp;</td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap>
<input type="checkbox" class="phpmaker" onClick="ew_SelectKey(this);">
</td>
<?php } ?>
<?php } ?>
<?php } ?>
	</tr>
<?php
	if ($tb_locations->CurrentAction == "add" || $tb_locations->CurrentAction == "copy") {
		$RowIndex = 1;
		if ($tb_locations->EventCancelled) { // Insert failed
			RestoreFormValues(); // Restore form values
		}

		// Init row class and style
		$tb_locations->CssClass = "ewTableEditRow"; // edit
		$tb_locations->CssStyle = "";

		// Init row event
		$tb_locations->RowClientEvents = "onmouseover='ew_MouseOver(this);' onmouseout='ew_MouseOut(this);' onclick='ew_Click(this);'";

		// Render add row
		$tb_locations->RowType = EW_ROWTYPE_ADD;
		RenderRow();
?>
	<tr<?php echo $tb_locations->DisplayAttributes() ?>>
		<!-- ID -->
		<td></td>
		<!-- LocationName -->
		<td>
<input type="text" name="x<?php echo $RowIndex ?>_LocationName" id="x<?php echo $RowIndex ?>_LocationName" title="" size="30" maxlength="45" value="<?php echo $tb_locations->LocationName->EditValue ?>"<?php echo $tb_locations->LocationName->EditAttributes() ?>>
</td>
		<!-- LocationRent -->
		<td>
<input type="text" name="x<?php echo $RowIndex ?>_LocationRent" id="x<?php echo $RowIndex ?>_LocationRent" title="" size="30" value="<?php echo $tb_locations->LocationRent->EditValue ?>"<?php echo $tb_locations->LocationRent->EditAttributes() ?>>
</td>
		<!-- PayRoll -->
		<td>
<input type="text" name="x<?php echo $RowIndex ?>_PayRoll" id="x<?php echo $RowIndex ?>_PayRoll" title="" size="30" value="<?php echo $tb_locations->PayRoll->EditValue ?>"<?php echo $tb_locations->PayRoll->EditAttributes() ?>>
</td>
		<!-- Utilities -->
		<td>
<input type="text" name="x<?php echo $RowIndex ?>_Utilities" id="x<?php echo $RowIndex ?>_Utilities" title="" size="30" value="<?php echo $tb_locations->Utilities->EditValue ?>"<?php echo $tb_locations->Utilities->EditAttributes() ?>>
</td>
<td colspan="<?php echo $OptionCnt ?>"><span class="phpmaker">
<a href="" onClick="if (ew_ValidateForm(document.ftb_locationslist)) document.ftb_locationslist.submit();return false;">Insert</a>&nbsp;<a href="tb_locationslist.php?a=cancel">Cancel</a>
<input type="hidden" name="a_list" id="a_list" value="insert">
</span></td>
	</tr>
<?php
}
?>
<?php
if (defined("EW_EXPORT_ALL") && $tb_locations->Export <> "") {
	$nStopRec = $nTotalRecs;
} else {
	$nStopRec = $nStartRec + $nDisplayRecs - 1; // Set the last record to display
}
$nRecCount = $nStartRec - 1;
if (!$rs->EOF) {
	$rs->MoveFirst();
	if (!$tb_locations->SelectLimit) $rs->Move($nStartRec - 1); // Move to first record directly
}
$RowCnt = 0;
if ($tb_locations->CurrentAction == "gridedit") $RowIndex = 0;
while (!$rs->EOF && $nRecCount < $nStopRec) {
	$nRecCount++;
	if (intval($nRecCount) >= intval($nStartRec)) {
		$RowCnt++;
		if ($tb_locations->CurrentAction == "gridedit") $RowIndex++;

	// Init row class and style
	$tb_locations->CssClass = "ewTableRow";
	$tb_locations->CssStyle = "";

	// Init row event
	$tb_locations->RowClientEvents = "onmouseover='ew_MouseOver(this);' onmouseout='ew_MouseOut(this);' onclick='ew_Click(this);'";

	// Display alternate color for rows
	if ($RowCnt % 2 == 0) {
		$tb_locations->CssClass = "ewTableAltRow";
	}
	LoadRowValues($rs); // Load row values
	$tb_locations->RowType = EW_ROWTYPE_VIEW; // Render view
	if ($tb_locations->CurrentAction == "gridedit") { // Grid edit
		$tb_locations->RowType = EW_ROWTYPE_EDIT; // Render edit
	}
		if ($tb_locations->RowType == EW_ROWTYPE_EDIT && $tb_locations->EventCancelled) { // Update failed
			if ($tb_locations->CurrentAction == "gridedit") {
				RestoreCurrentRowFormValues(); // Restore form values
			}
		}
		if ($tb_locations->RowType == EW_ROWTYPE_EDIT) { // Edit row
			$tb_locations->CssClass = "ewTableEditRow";
			$tb_locations->RowClientEvents = "onmouseover='this.edit=true;ew_MouseOver(this);' onmouseout='ew_MouseOut(this);' onclick='ew_Click(this);'";
		}
	RenderRow();
?>
	<!-- Table body -->
	<tr<?php echo $tb_locations->DisplayAttributes() ?>>
		<!-- ID -->
		<td<?php echo $tb_locations->ID->CellAttributes() ?>>
<?php if ($tb_locations->RowType == EW_ROWTYPE_EDIT) { // Edit Record ?>
<div<?php echo $tb_locations->ID->ViewAttributes() ?>><?php echo $tb_locations->ID->EditValue ?></div>
<input type="hidden" name="x<?php echo $RowIndex ?>_ID" id="x<?php echo $RowIndex ?>_ID" value="<?php echo ew_HtmlEncode($tb_locations->ID->CurrentValue) ?>">
<?php } else { ?>
<div<?php echo $tb_locations->ID->ViewAttributes() ?>><?php echo $tb_locations->ID->ViewValue ?></div>
<?php } ?>
</td>
		<!-- LocationName -->
		<td<?php echo $tb_locations->LocationName->CellAttributes() ?>>
<?php if ($tb_locations->RowType == EW_ROWTYPE_EDIT) { // Edit Record ?>
<input type="text" name="x<?php echo $RowIndex ?>_LocationName" id="x<?php echo $RowIndex ?>_LocationName" title="" size="30" maxlength="45" value="<?php echo $tb_locations->LocationName->EditValue ?>"<?php echo $tb_locations->LocationName->EditAttributes() ?>>
<?php } else { ?>
<div<?php echo $tb_locations->LocationName->ViewAttributes() ?>><?php echo $tb_locations->LocationName->ViewValue ?></div>
<?php } ?>
</td>
		<!-- LocationRent -->
		<td<?php echo $tb_locations->LocationRent->CellAttributes() ?>>
<?php if ($tb_locations->RowType == EW_ROWTYPE_EDIT) { // Edit Record ?>
<input type="text" name="x<?php echo $RowIndex ?>_LocationRent" id="x<?php echo $RowIndex ?>_LocationRent" title="" size="30" value="<?php echo $tb_locations->LocationRent->EditValue ?>"<?php echo $tb_locations->LocationRent->EditAttributes() ?>>
<?php } else { ?>
<div<?php echo $tb_locations->LocationRent->ViewAttributes() ?>><?php echo $tb_locations->LocationRent->ViewValue ?></div>
<?php } ?>
</td>
		<!-- PayRoll -->
		<td<?php echo $tb_locations->PayRoll->CellAttributes() ?>>
<?php if ($tb_locations->RowType == EW_ROWTYPE_EDIT) { // Edit Record ?>
<input type="text" name="x<?php echo $RowIndex ?>_PayRoll" id="x<?php echo $RowIndex ?>_PayRoll" title="" size="30" value="<?php echo $tb_locations->PayRoll->EditValue ?>"<?php echo $tb_locations->PayRoll->EditAttributes() ?>>
<?php } else { ?>
<div<?php echo $tb_locations->PayRoll->ViewAttributes() ?>><?php echo $tb_locations->PayRoll->ViewValue ?></div>
<?php } ?>
</td>
		<!-- Utilities -->
		<td<?php echo $tb_locations->Utilities->CellAttributes() ?>>
<?php if ($tb_locations->RowType == EW_ROWTYPE_EDIT) { // Edit Record ?>
<input type="text" name="x<?php echo $RowIndex ?>_Utilities" id="x<?php echo $RowIndex ?>_Utilities" title="" size="30" value="<?php echo $tb_locations->Utilities->EditValue ?>"<?php echo $tb_locations->Utilities->EditAttributes() ?>>
<?php } else { ?>
<div<?php echo $tb_locations->Utilities->ViewAttributes() ?>><?php echo $tb_locations->Utilities->ViewValue ?></div>
<?php } ?>
</td>
<?php if ($tb_locations->RowType == EW_ROWTYPE_EDIT) { ?>
<?php if ($tb_locations->CurrentAction == "gridedit") { ?>
<input type="hidden" name="k<?php echo $RowIndex ?>_key" id="k<?php echo $RowIndex ?>_key" value="<?php echo ew_HtmlEncode($tb_locations->ID->CurrentValue) ?>">
<?php } ?>
<?php } else { ?>
<?php if ($tb_locations->Export == "") { ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap><span class="phpmaker">
<a href="<?php echo $tb_locations->ViewUrl() ?>">View</a>
</span></td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap><span class="phpmaker">
<a href="<?php echo $tb_locations->EditUrl() ?>">Edit</a>
</span></td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap><span class="phpmaker">
<a href="<?php echo $tb_locations->CopyUrl() ?>">Copy</a>
</span></td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<?php if ($OptionCnt == 0 && $tb_locations->CurrentAction == "add") { ?>
<td nowrap>&nbsp;</td>
<?php } ?>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap><span class="phpmaker">
<a href="<?php echo $tb_locations->DeleteUrl() ?>">Delete</a>
</span></td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td nowrap><span class="phpmaker">
<input type="checkbox" name="key_m[]" id="key_m[]" value="<?php echo ew_HtmlEncode($tb_locations->ID->CurrentValue) ?>" class="phpmaker" onclick='ew_ClickMultiCheckbox(this);'>
</span></td>
<?php } ?>
<?php } ?>
<?php } ?>
	</tr>
<?php if ($tb_locations->RowType == EW_ROWTYPE_EDIT) { ?>
<?php } ?>
<?php
	}
	$rs->MoveNext();
}
?>
</table>
<?php if ($tb_locations->Export == "") { ?>
<table>
	<tr><td><span class="phpmaker">
<?php if ($tb_locations->CurrentAction <> "gridedit") { // Not grid edit mode ?>
<?php if ($Security->IsLoggedIn()) { ?>
<a href="tb_locationsadd.php">Add</a>&nbsp;&nbsp;
<a href="tb_locationslist.php?a=add">Inline Add</a>&nbsp;&nbsp;
<?php } ?>
<?php if ($nTotalRecs > 0) { ?>
<?php if ($Security->IsLoggedIn()) { ?>
<a href="" onClick="if (!ew_Selected(document.ftb_locationslist)) alert('No records selected'); else {document.ftb_locationslist.action='tb_locationsupdate.php';document.ftb_locationslist.encoding='application/x-www-form-urlencoded';document.ftb_locationslist.submit();};return false;">Update Selected Records</a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<?php if ($nTotalRecs > 0) { ?>
<a href="tb_locationslist.php?a=gridedit">Grid Edit</a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
<?php } else { // Grid edit mode ?>
<a href="" onClick="if (ew_ValidateForm(document.ftb_locationslist)) document.ftb_locationslist.submit();return false;">Save</a>&nbsp;&nbsp;
<a href="tb_locationslist.php?a=cancel">Cancel</a>&nbsp;&nbsp;
<?php } ?>
	</span></td></tr>
</table>
<?php } ?>
<?php } ?>
<?php if ($tb_locations->CurrentAction == "add" || $tb_locations->CurrentAction == "copy") { ?>
<input type="hidden" name="key_count" id="key_count" value="<?php echo $RowIndex ?>">
<?php } ?>
<?php if ($tb_locations->CurrentAction == "gridedit") { ?>
<input type="hidden" name="a_list" id="a_list" value="gridupdate">
<input type="hidden" name="key_count" id="key_count" value="<?php echo $RowIndex ?>">
<?php } ?>
</form>
<?php

// Close recordset and connection
if ($rs) $rs->Close();
?>
<?php if ($tb_locations->Export == "") { ?>
<form action="tb_locationslist.php" name="ewpagerform" id="ewpagerform">
<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td nowrap>
<?php if (!isset($Pager)) $Pager = new cPrevNextPager($nStartRec, $nDisplayRecs, $nTotalRecs) ?>
<?php if ($Pager->RecordCount > 0) { ?>
	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="phpmaker">Page&nbsp;</span></td>
<!--first page button-->
	<?php if ($Pager->FirstButton->Enabled) { ?>
	<td><a href="tb_locationslist.php?start=<?php echo $Pager->FirstButton->Start ?>"><img src="images/first.gif" alt="First" width="16" height="16" border="0"></a></td>
	<?php } else { ?>
	<td><img src="images/firstdisab.gif" alt="First" width="16" height="16" border="0"></td>
	<?php } ?>
<!--previous page button-->
	<?php if ($Pager->PrevButton->Enabled) { ?>
	<td><a href="tb_locationslist.php?start=<?php echo $Pager->PrevButton->Start ?>"><img src="images/prev.gif" alt="Previous" width="16" height="16" border="0"></a></td>
	<?php } else { ?>
	<td><img src="images/prevdisab.gif" alt="Previous" width="16" height="16" border="0"></td>
	<?php } ?>
<!--current page number-->
	<td><input type="text" name="<?php echo EW_TABLE_PAGE_NO ?>" id="<?php echo EW_TABLE_PAGE_NO ?>" value="<?php echo $Pager->CurrentPage ?>" size="4"></td>
<!--next page button-->
	<?php if ($Pager->NextButton->Enabled) { ?>
	<td><a href="tb_locationslist.php?start=<?php echo $Pager->NextButton->Start ?>"><img src="images/next.gif" alt="Next" width="16" height="16" border="0"></a></td>	
	<?php } else { ?>
	<td><img src="images/nextdisab.gif" alt="Next" width="16" height="16" border="0"></td>
	<?php } ?>
<!--last page button-->
	<?php if ($Pager->LastButton->Enabled) { ?>
	<td><a href="tb_locationslist.php?start=<?php echo $Pager->LastButton->Start ?>"><img src="images/last.gif" alt="Last" width="16" height="16" border="0"></a></td>	
	<?php } else { ?>
	<td><img src="images/lastdisab.gif" alt="Last" width="16" height="16" border="0"></td>
	<?php } ?>
	<td><span class="phpmaker">&nbsp;of <?php echo $Pager->PageCount ?></span></td>
	</tr></table>
	<span class="phpmaker">Records <?php echo $Pager->FromIndex ?> to <?php echo $Pager->ToIndex ?> of <?php echo $Pager->RecordCount ?></span>
<?php } else { ?>
	<?php if ($sSrchWhere == "0=101") { ?>
	<span class="phpmaker">Please enter search criteria</span>
	<?php } else { ?>
	<span class="phpmaker">No records found</span>
	<?php } ?>
<?php } ?>
		</td>
	</tr>
</table>
</form>
<?php } ?>
<?php if ($tb_locations->Export == "") { ?>
<?php } ?>
<?php if ($tb_locations->Export == "") { ?>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php } ?>
<?php include "footer.php" ?>
<?php

// If control is passed here, simply terminate the page without redirect
Page_Terminate();

// -----------------------------------------------------------------
//  Subroutine Page_Terminate
//  - called when exit page
//  - clean up connection and objects
//  - if url specified, redirect to url, otherwise end response
function Page_Terminate($url = "") {
	global $conn;

	// Page unload event, used in current page
	Page_Unload();

	// Global page unloaded event (in userfn*.php)
	Page_Unloaded();

	 // Close Connection
	$conn->Close();

	// Go to url if specified
	if ($url <> "") {
		ob_end_clean();
		header("Location: $url");
	}
	exit();
}
?>
<?php

//  Exit out of inline mode
function ClearInlineMode() {
	global $tb_locations;
	$tb_locations->CurrentAction = ""; // Clear action
	$_SESSION[EW_SESSION_INLINE_MODE] = ""; // Clear inline mode
}

// Switch to Grid Edit Mode
function GridEditMode() {
	$_SESSION[EW_SESSION_INLINE_MODE] = "gridedit"; // Enable grid edit
}

// Switch to Inline Add Mode
function InlineAddMode() {
	global $Security, $tb_locations;
	$tb_locations->CurrentAction = "add";
	$_SESSION[EW_SESSION_INLINE_MODE] = "add"; // Enable inline add
}

// Peform update to inline add/copy record
function InlineInsert() {
	global $objForm, $tb_locations;
	$objForm->Index = 1;
	LoadFormValues(); // Get form values
	$tb_locations->SendEmail = TRUE; // Send email on add success
	if (AddRow()) { // Add record
		$_SESSION[EW_SESSION_MESSAGE] = "Add New Record Successful"; // Set add success message
		ClearInlineMode(); // Clear inline add mode
	} else { // Add failed
		$tb_locations->EventCancelled = TRUE; // Set event cancelled
		$tb_locations->CurrentAction = "add"; // Stay in add mode
	}
}

// Peform update to grid
function GridUpdate() {
	global $conn, $objForm, $tb_locations;
	$rowindex = 1;
	$bGridUpdate = TRUE;

	// Begin transaction
	$conn->BeginTrans();
	$sKey = "";

	// Update row index and get row key
	$objForm->Index = $rowindex;
	$sThisKey = strval($objForm->GetValue("k_key"));

	// Update all rows based on key
	while ($sThisKey <> "") {

		// Load all values & keys
		LoadFormValues(); // Get form values
		if (LoadKeyValues($sThisKey)) { // Get key values
			$tb_locations->SendEmail = FALSE; // Do not send email on update success
			$bGridUpdate = EditRow(); // Update this row
		} else {
			$bGridUpdate = FALSE; // update failed
		}
		if ($bGridUpdate) {
			if ($sKey <> "") $sKey .= ", ";
			$sKey .= $sThisKey;
		} else {
			break;
		}

		// Update row index and get row key
		$rowindex++; // next row
		$objForm->Index = $rowindex;
		$sThisKey = strval($objForm->GetValue("k_key"));
	}
	if ($bGridUpdate) {
		$conn->CommitTrans(); // Commit transaction
		$_SESSION[EW_SESSION_MESSAGE] = "Update successful"; // Set update success message
		ClearInlineMode(); // Clear inline edit mode
	} else {
		$conn->RollbackTrans(); // Rollback transaction
		if (@$_SESSION[EW_SESSION_MESSAGE] == "") {
			$_SESSION[EW_SESSION_MESSAGE] = "Update failed"; // Set update failed message
		}
		$tb_locations->EventCancelled = TRUE; // Set event cancelled
		$tb_locations->CurrentAction = "gridedit"; // Stay in gridedit mode
	}
}

// Load key values
function LoadKeyValues($sKey) {
	global $tb_locations;
	$arrKeyFlds = explode(EW_COMPOSITE_KEY_SEPARATOR, strval($sKey));
	if (count($arrKeyFlds) >= 1) {
		$tb_locations->ID->setFormValue($arrKeyFlds[0]);
		if (!is_numeric($tb_locations->ID->FormValue)) {
			return FALSE;
		}
	}
	return TRUE;
}

// Restore form values for current row
function RestoreCurrentRowFormValues() {
	global $objForm, $tb_locations;

//	Dim sKey, arrKeyFlds
//	Dim rowindex
//	Dim elem
	// Update row index and get row key

	$rowindex = 1;
	$objForm->Index = $rowindex;
	$sKey = strval($objForm->GetValue("k_key"));
	while ($sKey <> "") {
		$arrKeyFlds = explode(EW_COMPOSITE_KEY_SEPARATOR, strval($sKey));
		if (count($arrKeyFlds) >= 1) {
			if (strval($arrKeyFlds[0]) == strval($tb_locations->ID->CurrentValue)) {
				$objForm->Index = $rowindex;
				LoadFormValues(); // Load form values
				return;
			}
		}

		// Update row index and get row key
		$rowindex++;
		$objForm->Index = $rowindex;
		$sKey = strval($objForm->GetValue("k_key"));
	}
}

// Return Basic Search sql
function BasicSearchSQL($Keyword) {
	$sKeyword = ew_AdjustSql($Keyword);
	$sql = "";
	$sql .= "`LocationName` LIKE '%" . $sKeyword . "%' OR ";
	if (substr($sql, -4) == " OR ") $sql = substr($sql, 0, strlen($sql)-4);
	return $sql;
}

// Return Basic Search Where based on search keyword and type
function BasicSearchWhere() {
	global $Security, $tb_locations;
	$sSearchStr = "";
	$sSearchKeyword = ew_StripSlashes(@$_GET[EW_TABLE_BASIC_SEARCH]);
	$sSearchType = @$_GET[EW_TABLE_BASIC_SEARCH_TYPE];
	if ($sSearchKeyword <> "") {
		$sSearch = trim($sSearchKeyword);
		if ($sSearchType <> "") {
			while (strpos($sSearch, "  ") !== FALSE)
				$sSearch = str_replace("  ", " ", $sSearch);
			$arKeyword = explode(" ", trim($sSearch));
			foreach ($arKeyword as $sKeyword) {
				if ($sSearchStr <> "") $sSearchStr .= " " . $sSearchType . " ";
				$sSearchStr .= "(" . BasicSearchSQL($sKeyword) . ")";
			}
		} else {
			$sSearchStr = BasicSearchSQL($sSearch);
		}
	}
	if ($sSearchKeyword <> "") {
		$tb_locations->setBasicSearchKeyword($sSearchKeyword);
		$tb_locations->setBasicSearchType($sSearchType);
	}
	return $sSearchStr;
}

// Clear all search parameters
function ResetSearchParms() {

	// Clear search where
	global $tb_locations;
	$sSrchWhere = "";
	$tb_locations->setSearchWhere($sSrchWhere);

	// Clear basic search parameters
	ResetBasicSearchParms();
}

// Clear all basic search parameters
function ResetBasicSearchParms() {

	// Clear basic search parameters
	global $tb_locations;
	$tb_locations->setBasicSearchKeyword("");
	$tb_locations->setBasicSearchType("");
}

// Restore all search parameters
function RestoreSearchParms() {
	global $sSrchWhere, $tb_locations;
	$sSrchWhere = $tb_locations->getSearchWhere();
}

// Set up Sort parameters based on Sort Links clicked
function SetUpSortOrder() {
	global $tb_locations;

	// Check for an Order parameter
	if (@$_GET["order"] <> "") {
		$tb_locations->CurrentOrder = ew_StripSlashes(@$_GET["order"]);
		$tb_locations->CurrentOrderType = @$_GET["ordertype"];

		// Field ID
		$tb_locations->UpdateSort($tb_locations->ID);

		// Field LocationName
		$tb_locations->UpdateSort($tb_locations->LocationName);

		// Field LocationRent
		$tb_locations->UpdateSort($tb_locations->LocationRent);

		// Field PayRoll
		$tb_locations->UpdateSort($tb_locations->PayRoll);

		// Field Utilities
		$tb_locations->UpdateSort($tb_locations->Utilities);
		$tb_locations->setStartRecordNumber(1); // Reset start position
	}
	$sOrderBy = $tb_locations->getSessionOrderBy(); // Get order by from Session
	if ($sOrderBy == "") {
		if ($tb_locations->SqlOrderBy() <> "") {
			$sOrderBy = $tb_locations->SqlOrderBy();
			$tb_locations->setSessionOrderBy($sOrderBy);
		}
	}
}

// Reset command based on querystring parameter cmd=
// - RESET: reset search parameters
// - RESETALL: reset search & master/detail parameters
// - RESETSORT: reset sort parameters
function ResetCmd() {
	global $sDbMasterFilter, $sDbDetailFilter, $nStartRec, $sOrderBy;
	global $tb_locations;

	// Get reset cmd
	if (@$_GET["cmd"] <> "") {
		$sCmd = $_GET["cmd"];

		// Reset search criteria
		if (strtolower($sCmd) == "reset" || strtolower($sCmd) == "resetall") {
			ResetSearchParms();
		}

		// Reset Sort Criteria
		if (strtolower($sCmd) == "resetsort") {
			$sOrderBy = "";
			$tb_locations->setSessionOrderBy($sOrderBy);
			$tb_locations->ID->setSort("");
			$tb_locations->LocationName->setSort("");
			$tb_locations->LocationRent->setSort("");
			$tb_locations->PayRoll->setSort("");
			$tb_locations->Utilities->setSort("");
		}

		// Reset start position
		$nStartRec = 1;
		$tb_locations->setStartRecordNumber($nStartRec);
	}
}
?>
<?php

// Set up Starting Record parameters based on Pager Navigation
function SetUpStartRec() {
	global $nDisplayRecs, $nStartRec, $nTotalRecs, $nPageNo, $tb_locations;
	if ($nDisplayRecs == 0) return;

	// Check for a START parameter
	if (@$_GET[EW_TABLE_START_REC] <> "") {
		$nStartRec = $_GET[EW_TABLE_START_REC];
		$tb_locations->setStartRecordNumber($nStartRec);
	} elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
		$nPageNo = $_GET[EW_TABLE_PAGE_NO];
		if (is_numeric($nPageNo)) {
			$nStartRec = ($nPageNo-1)*$nDisplayRecs+1;
			if ($nStartRec <= 0) {
				$nStartRec = 1;
			} elseif ($nStartRec >= intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1) {
				$nStartRec = intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1;
			}
			$tb_locations->setStartRecordNumber($nStartRec);
		} else {
			$nStartRec = $tb_locations->getStartRecordNumber();
		}
	} else {
		$nStartRec = $tb_locations->getStartRecordNumber();
	}

	// Check if correct start record counter
	if (!is_numeric($nStartRec) || $nStartRec == "") { // Avoid invalid start record counter
		$nStartRec = 1; // Reset start record counter
		$tb_locations->setStartRecordNumber($nStartRec);
	} elseif (intval($nStartRec) > intval($nTotalRecs)) { // Avoid starting record > total records
		$nStartRec = intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1; // Point to last page first record
		$tb_locations->setStartRecordNumber($nStartRec);
	} elseif (($nStartRec-1) % $nDisplayRecs <> 0) {
		$nStartRec = intval(($nStartRec-1)/$nDisplayRecs)*$nDisplayRecs+1; // Point to page boundary
		$tb_locations->setStartRecordNumber($nStartRec);
	}
}
?>
<?php

// Load default values
function LoadDefaultValues() {
	global $tb_locations;
}
?>
<?php

// Load form values
function LoadFormValues() {

	// Load from form
	global $objForm, $tb_locations;
	$tb_locations->ID->setFormValue($objForm->GetValue("x_ID"));
	$tb_locations->LocationName->setFormValue($objForm->GetValue("x_LocationName"));
	$tb_locations->LocationRent->setFormValue($objForm->GetValue("x_LocationRent"));
	$tb_locations->PayRoll->setFormValue($objForm->GetValue("x_PayRoll"));
	$tb_locations->Utilities->setFormValue($objForm->GetValue("x_Utilities"));
}

// Restore form values
function RestoreFormValues() {
	global $tb_locations;
	$tb_locations->ID->CurrentValue = $tb_locations->ID->FormValue;
	$tb_locations->LocationName->CurrentValue = $tb_locations->LocationName->FormValue;
	$tb_locations->LocationRent->CurrentValue = $tb_locations->LocationRent->FormValue;
	$tb_locations->PayRoll->CurrentValue = $tb_locations->PayRoll->FormValue;
	$tb_locations->Utilities->CurrentValue = $tb_locations->Utilities->FormValue;
}
?>
<?php

// Load recordset
function LoadRecordset($offset = -1, $rowcnt = -1) {
	global $conn, $tb_locations;

	// Call Recordset Selecting event
	$tb_locations->Recordset_Selecting($tb_locations->CurrentFilter);

	// Load list page sql
	$sSql = $tb_locations->SelectSQL();
	if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";

	// Load recordset
	$conn->raiseErrorFn = 'ew_ErrorFn';	
	$rs = $conn->Execute($sSql);
	$conn->raiseErrorFn = '';

	// Call Recordset Selected event
	$tb_locations->Recordset_Selected($rs);
	return $rs;
}
?>
<?php

// Load row based on key values
function LoadRow() {
	global $conn, $Security, $tb_locations;
	$sFilter = $tb_locations->SqlKeyFilter();
	if (!is_numeric($tb_locations->ID->CurrentValue)) {
		return FALSE; // Invalid key, exit
	}
	$sFilter = str_replace("@ID@", ew_AdjustSql($tb_locations->ID->CurrentValue), $sFilter); // Replace key value

	// Call Row Selecting event
	$tb_locations->Row_Selecting($sFilter);

	// Load sql based on filter
	$tb_locations->CurrentFilter = $sFilter;
	$sSql = $tb_locations->SQL();
	if ($rs = $conn->Execute($sSql)) {
		if ($rs->EOF) {
			$LoadRow = FALSE;
		} else {
			$LoadRow = TRUE;
			$rs->MoveFirst();
			LoadRowValues($rs); // Load row values

			// Call Row Selected event
			$tb_locations->Row_Selected($rs);
		}
		$rs->Close();
	} else {
		$LoadRow = FALSE;
	}
	return $LoadRow;
}

// Load row values from recordset
function LoadRowValues(&$rs) {
	global $tb_locations;
	$tb_locations->ID->setDbValue($rs->fields('ID'));
	$tb_locations->LocationName->setDbValue($rs->fields('LocationName'));
	$tb_locations->LocationRent->setDbValue($rs->fields('LocationRent'));
	$tb_locations->PayRoll->setDbValue($rs->fields('PayRoll'));
	$tb_locations->Utilities->setDbValue($rs->fields('Utilities'));
	$tb_locations->CreateDate->setDbValue($rs->fields('CreateDate'));
}
?>
<?php

// Render row values based on field settings
function RenderRow() {
	global $conn, $Security, $tb_locations;

	// Call Row Rendering event
	$tb_locations->Row_Rendering();

	// Common render codes for all row types
	// ID

	$tb_locations->ID->CellCssStyle = "";
	$tb_locations->ID->CellCssClass = "";

	// LocationName
	$tb_locations->LocationName->CellCssStyle = "";
	$tb_locations->LocationName->CellCssClass = "";

	// LocationRent
	$tb_locations->LocationRent->CellCssStyle = "";
	$tb_locations->LocationRent->CellCssClass = "";

	// PayRoll
	$tb_locations->PayRoll->CellCssStyle = "";
	$tb_locations->PayRoll->CellCssClass = "";

	// Utilities
	$tb_locations->Utilities->CellCssStyle = "";
	$tb_locations->Utilities->CellCssClass = "";
	if ($tb_locations->RowType == EW_ROWTYPE_VIEW) { // View row

		// ID
		$tb_locations->ID->ViewValue = $tb_locations->ID->CurrentValue;
		$tb_locations->ID->CssStyle = "";
		$tb_locations->ID->CssClass = "";
		$tb_locations->ID->ViewCustomAttributes = "";

		// LocationName
		$tb_locations->LocationName->ViewValue = $tb_locations->LocationName->CurrentValue;
		$tb_locations->LocationName->CssStyle = "";
		$tb_locations->LocationName->CssClass = "";
		$tb_locations->LocationName->ViewCustomAttributes = "";

		// LocationRent
		$tb_locations->LocationRent->ViewValue = $tb_locations->LocationRent->CurrentValue;
		$tb_locations->LocationRent->ViewValue = ew_FormatCurrency($tb_locations->LocationRent->ViewValue, 2, -2, -2, 0);
		$tb_locations->LocationRent->CssStyle = "";
		$tb_locations->LocationRent->CssClass = "";
		$tb_locations->LocationRent->ViewCustomAttributes = "";

		// PayRoll
		$tb_locations->PayRoll->ViewValue = $tb_locations->PayRoll->CurrentValue;
		$tb_locations->PayRoll->ViewValue = ew_FormatCurrency($tb_locations->PayRoll->ViewValue, 2, -2, -2, -2);
		$tb_locations->PayRoll->CssStyle = "";
		$tb_locations->PayRoll->CssClass = "";
		$tb_locations->PayRoll->ViewCustomAttributes = "";

		// Utilities
		$tb_locations->Utilities->ViewValue = $tb_locations->Utilities->CurrentValue;
		$tb_locations->Utilities->ViewValue = ew_FormatCurrency($tb_locations->Utilities->ViewValue, 2, -2, -2, -2);
		$tb_locations->Utilities->CssStyle = "";
		$tb_locations->Utilities->CssClass = "";
		$tb_locations->Utilities->ViewCustomAttributes = "";

		// ID
		$tb_locations->ID->HrefValue = "";

		// LocationName
		$tb_locations->LocationName->HrefValue = "";

		// LocationRent
		$tb_locations->LocationRent->HrefValue = "";

		// PayRoll
		$tb_locations->PayRoll->HrefValue = "";

		// Utilities
		$tb_locations->Utilities->HrefValue = "";
	} elseif ($tb_locations->RowType == EW_ROWTYPE_ADD) { // Add row

		// ID
		$tb_locations->ID->EditCustomAttributes = "";
		$tb_locations->ID->EditValue = $tb_locations->ID->CurrentValue;

		// LocationName
		$tb_locations->LocationName->EditCustomAttributes = "";
		$tb_locations->LocationName->EditValue = ew_HtmlEncode($tb_locations->LocationName->CurrentValue);

		// LocationRent
		$tb_locations->LocationRent->EditCustomAttributes = "";
		$tb_locations->LocationRent->EditValue = $tb_locations->LocationRent->CurrentValue;

		// PayRoll
		$tb_locations->PayRoll->EditCustomAttributes = "";
		$tb_locations->PayRoll->EditValue = $tb_locations->PayRoll->CurrentValue;

		// Utilities
		$tb_locations->Utilities->EditCustomAttributes = "";
		$tb_locations->Utilities->EditValue = $tb_locations->Utilities->CurrentValue;
	} elseif ($tb_locations->RowType == EW_ROWTYPE_EDIT) { // Edit row

		// ID
		$tb_locations->ID->EditCustomAttributes = "";
		$tb_locations->ID->EditValue = $tb_locations->ID->CurrentValue;
		$tb_locations->ID->CssStyle = "";
		$tb_locations->ID->CssClass = "";
		$tb_locations->ID->ViewCustomAttributes = "";

		// LocationName
		$tb_locations->LocationName->EditCustomAttributes = "";
		$tb_locations->LocationName->EditValue = ew_HtmlEncode($tb_locations->LocationName->CurrentValue);

		// LocationRent
		$tb_locations->LocationRent->EditCustomAttributes = "";
		$tb_locations->LocationRent->EditValue = $tb_locations->LocationRent->CurrentValue;

		// PayRoll
		$tb_locations->PayRoll->EditCustomAttributes = "";
		$tb_locations->PayRoll->EditValue = $tb_locations->PayRoll->CurrentValue;

		// Utilities
		$tb_locations->Utilities->EditCustomAttributes = "";
		$tb_locations->Utilities->EditValue = $tb_locations->Utilities->CurrentValue;
	} elseif ($tb_locations->RowType == EW_ROWTYPE_SEARCH) { // Search row
	}

	// Call Row Rendered event
	$tb_locations->Row_Rendered();
}
?>
<?php

// Update record based on key values
function EditRow() {
	global $conn, $Security, $tb_locations;
	$sFilter = $tb_locations->SqlKeyFilter();
	if (!is_numeric($tb_locations->ID->CurrentValue)) {
		return FALSE;
	}
	$sFilter = str_replace("@ID@", ew_AdjustSql($tb_locations->ID->CurrentValue), $sFilter); // Replace key value
	$tb_locations->CurrentFilter = $sFilter;
	$sSql = $tb_locations->SQL();
	$conn->raiseErrorFn = 'ew_ErrorFn';
	$rs = $conn->Execute($sSql);
	$conn->raiseErrorFn = '';
	if ($rs === FALSE)
		return FALSE;
	if ($rs->EOF) {
		$EditRow = FALSE; // Update Failed
	} else {

		// Save old values
		$rsold =& $rs->fields;
		$rsnew = array();

		// Field ID
		// Field LocationName

		$tb_locations->LocationName->SetDbValueDef($tb_locations->LocationName->CurrentValue, NULL);
		$rsnew['LocationName'] =& $tb_locations->LocationName->DbValue;

		// Field LocationRent
		$tb_locations->LocationRent->SetDbValueDef($tb_locations->LocationRent->CurrentValue, NULL);
		$rsnew['LocationRent'] =& $tb_locations->LocationRent->DbValue;

		// Field PayRoll
		$tb_locations->PayRoll->SetDbValueDef($tb_locations->PayRoll->CurrentValue, NULL);
		$rsnew['PayRoll'] =& $tb_locations->PayRoll->DbValue;

		// Field Utilities
		$tb_locations->Utilities->SetDbValueDef($tb_locations->Utilities->CurrentValue, NULL);
		$rsnew['Utilities'] =& $tb_locations->Utilities->DbValue;

		// Call Row Updating event
		$bUpdateRow = $tb_locations->Row_Updating($rsold, $rsnew);
		if ($bUpdateRow) {
			$conn->raiseErrorFn = 'ew_ErrorFn';
			$EditRow = $conn->Execute($tb_locations->UpdateSQL($rsnew));
			$conn->raiseErrorFn = '';
		} else {
			if ($tb_locations->CancelMessage <> "") {
				$_SESSION[EW_SESSION_MESSAGE] = $tb_locations->CancelMessage;
				$tb_locations->CancelMessage = "";
			} else {
				$_SESSION[EW_SESSION_MESSAGE] = "Update cancelled";
			}
			$EditRow = FALSE;
		}
	}

	// Call Row Updated event
	if ($EditRow) {
		$tb_locations->Row_Updated($rsold, $rsnew);
	}
	$rs->Close();
	return $EditRow;
}
?>
<?php

// Add record
function AddRow() {
	global $conn, $Security, $tb_locations;

	// Check for duplicate key
	$bCheckKey = TRUE;
	$sFilter = $tb_locations->SqlKeyFilter();
	if (trim(strval($tb_locations->ID->CurrentValue)) == "") {
		$bCheckKey = FALSE;
	} else {
		$sFilter = str_replace("@ID@", ew_AdjustSql($tb_locations->ID->CurrentValue), $sFilter); // Replace key value
	}
	if (!is_numeric($tb_locations->ID->CurrentValue)) {
		$bCheckKey = FALSE;
	}
	if ($bCheckKey) {
		$rsChk = $tb_locations->LoadRs($sFilter);
		if ($rsChk && !$rsChk->EOF) {
			$_SESSION[EW_SESSION_MESSAGE] = "Duplicate value for primary key";
			$rsChk->Close();
			return FALSE;
		}
	}
	$rsnew = array();

	// Field ID
	// Field LocationName

	$tb_locations->LocationName->SetDbValueDef($tb_locations->LocationName->CurrentValue, NULL);
	$rsnew['LocationName'] =& $tb_locations->LocationName->DbValue;

	// Field LocationRent
	$tb_locations->LocationRent->SetDbValueDef($tb_locations->LocationRent->CurrentValue, NULL);
	$rsnew['LocationRent'] =& $tb_locations->LocationRent->DbValue;

	// Field PayRoll
	$tb_locations->PayRoll->SetDbValueDef($tb_locations->PayRoll->CurrentValue, NULL);
	$rsnew['PayRoll'] =& $tb_locations->PayRoll->DbValue;

	// Field Utilities
	$tb_locations->Utilities->SetDbValueDef($tb_locations->Utilities->CurrentValue, NULL);
	$rsnew['Utilities'] =& $tb_locations->Utilities->DbValue;

	// Call Row Inserting event
	$bInsertRow = $tb_locations->Row_Inserting($rsnew);
	if ($bInsertRow) {
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$AddRow = $conn->Execute($tb_locations->InsertSQL($rsnew));
		$conn->raiseErrorFn = '';
	} else {
		if ($tb_locations->CancelMessage <> "") {
			$_SESSION[EW_SESSION_MESSAGE] = $tb_locations->CancelMessage;
			$tb_locations->CancelMessage = "";
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = "Insert cancelled";
		}
		$AddRow = FALSE;
	}
	if ($AddRow) {
		$tb_locations->ID->setDbValue($conn->Insert_ID());
		$rsnew['ID'] =& $tb_locations->ID->DbValue;

		// Call Row Inserted event
		$tb_locations->Row_Inserted($rsnew);
	}
	return $AddRow;
}
?>
<?php

// Export data in Xml or Csv format
function ExportData() {
	global $nTotalRecs, $nStartRec, $nStopRec, $nTotalRecs, $nDisplayRecs, $tb_locations;
	$sCsvStr = "";
	$rs = LoadRecordset();
	$nTotalRecs = $rs->RecordCount();
	$nStartRec = 1;

	// Export all
	if (defined("EW_EXPORT_ALL")) {
		$nStopRec = $nTotalRecs;
	} else { // Export 1 page only
		SetUpStartRec(); // Set Up Start Record Position

		// Set the last record to display
		if ($nDisplayRecs < 0) {
			$nStopRec = $nTotalRecs;
		} else {
			$nStopRec = $nStartRec + $nDisplayRecs - 1;
		}
	}
	if ($tb_locations->Export == "csv") {
		$sCsvStr .= "ID" . ",";
		$sCsvStr .= "LocationName" . ",";
		$sCsvStr .= "LocationRent" . ",";
		$sCsvStr .= "PayRoll" . ",";
		$sCsvStr .= "Utilities" . ",";
		$sCsvStr = substr($sCsvStr, 0, strlen($sCsvStr)-1); // Remove last comma
		$sCsvStr .= "\n";
	}

	// Move to first record directly for performance reason
	$nRecCount = $nStartRec - 1;
	if (!$rs->EOF) {
		$rs->MoveFirst();
		$rs->Move($nStartRec - 1);
	}
	while (!$rs->EOF && $nRecCount < $nStopRec) {
		$nRecCount++;
		if (intval($nRecCount) >= intval($nStartRec)) {
			LoadRowValues($rs);
			if ($tb_locations->Export == "csv") {
				$sCsvStr .= '"' . str_replace('"', '""', strval($tb_locations->ID->CurrentValue)) . '",';
				$sCsvStr .= '"' . str_replace('"', '""', strval($tb_locations->LocationName->CurrentValue)) . '",';
				$sCsvStr .= '"' . str_replace('"', '""', strval($tb_locations->LocationRent->CurrentValue)) . '",';
				$sCsvStr .= '"' . str_replace('"', '""', strval($tb_locations->PayRoll->CurrentValue)) . '",';
				$sCsvStr .= '"' . str_replace('"', '""', strval($tb_locations->Utilities->CurrentValue)) . '",';
				$sCsvStr = substr($sCsvStr, 0, strlen($sCsvStr)-1); // Remove last comma
				$sCsvStr .= "\n";
			}
		}
		$rs->MoveNext();
	}

	// Close recordset
	$rs->Close();
	if ($tb_locations->Export == "csv") {
		echo $sCsvStr;
	}
}
?>
<?php

// Page Load event
function Page_Load() {

	//echo "Page Load";
}

// Page Unload event
function Page_Unload() {

	//echo "Page Unload";
}
?>
